package org.urey.dao.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.urey.dao.dao.Test1Dao;
import org.urey.dao.dao.TestDao;
import org.urey.dao.entity.Test;

@SuppressWarnings(value = { "rawtypes", "unchecked" })
public class TestService {

	@Autowired
	private TestDao dao;

	@Autowired(required = false)
	private Test1Dao test1Dao;

	public <T extends Test> void test(Class<T> clazz) {
		try {
			T test = clazz.newInstance();
			test.setName("1");
			dao.save(test);

			List<Test> list = dao.findAll();
			System.out.println(list.size());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public <T extends Test> T save(Class<T> clazz, String name) {
		try {
			T test = clazz.newInstance();
			test.setName(name);
			test = (T) dao.save(test);
			return test;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public Test get(Long id) {
		try {
			return (Test) dao.findOne(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
